package com.alibaba.springbootrbac.utils;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private Integer code;  // 状态码
    private String message; // 提示信息
    private T data; // 返回数据

    // 成功
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(1000);
        result.setMessage("操作成功");
        result.setData(data);
        return result;
    }

    // 成功 - 自定义消息
    public static <T> Result<T> success(String message, T data) {
        Result<T> result = new Result<>();
        result.setCode(1000);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    // 失败
    public static <T> Result<T> failure(Integer code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    // 失败 - 默认 500
    public static <T> Result<T> failure(String message) {
        return failure(5001, message);
    }
}
